#include "AreaChartLegend.h"
#include <QGraphicsView>
#include "../../common/utility.h"
#include <QMessageBox>

namespace LightChart
{
    qwtAreaChartLegend::qwtAreaChartLegend(const std::vector<QColor>* colors, const std::vector<std::string>* labels, QWidget* parent)
    : QwtLegend(parent)
    {
	Ui_qwtAreaChartLegend::setupUi(this);
	if(labels->empty()) QMessageBox::critical(this, "Error", "Labels empty!!!");
	table->setColumnCount(1);
	if(labels->size() != colors->size()) QMessageBox::critical(this, "Error", "Labels' size is not equal colors' size");
	else
	{
	    for(unsigned i = 0; i < labels->size(); ++i)
	    {
		table->setRowCount(table->rowCount() + 1);
		QLabel* label = new QLabel((*labels)[i].c_str(),this);
		label->setStyleSheet(getBgColorStyleSheet((*colors)[i]));
		table->setCellWidget(i,0,label);
	    }
	}
    }

    qwtAreaChartLegend::qwtAreaChartLegend(QWidget* parent)
    : QwtLegend(parent)
    {
	Ui_qwtAreaChartLegend::setupUi(this);
    }
}
